package com.mvp.shq.washer.ui.resetPwd;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.mvp.shq.washer.R;
import com.mvp.shq.washer.base.BaseActivity;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.utils.EventCode;
import com.mvp.shq.washer.utils.T;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ResetPwdActivity extends BaseActivity<Presenter, Model> implements ResetPwdConstract.View {


    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.et_pwd1)
    EditText etPwd1;
    @BindView(R.id.et_pwd2)
    EditText etPwd2;

    @Override
    public int getLayoutId() {
        return R.layout.activity_reset_pwd;
    }

    @Override
    public void initView() {
        StatusBarUtil.setColor(this, ContextCompat.getColor(context, R.color.white), 0);

    }


    @OnClick({R.id.back, R.id.btn_commit})
    public void onViewClicked(View view) {
        String pwd = etPwd.getText().toString();
        String pwd1 = etPwd1.getText().toString();
        String pwd2 = etPwd2.getText().toString();
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.btn_commit:
                if (TextUtils.isEmpty(pwd) || TextUtils.isEmpty(pwd1) || TextUtils.isEmpty(pwd2)){
                    T.show("请检查输入");
                    return;
                }
                if (!pwd2.equals(pwd1)){
                    T.show("两次输入的密码不同");
                    return;
                }
                if (pwd1.length() < 6){
                    T.show("密码长度不能小于6为");
                    return;
                }
                showLoadingDialog(true);
                presenter.commit(pwd,pwd1);
                break;
        }
    }

    @Override
    public void resetSuccess() {
        finish();
        RxBus.get().send(EventCode.DEL_JPUSH_ALIAS);
    }

    @Override
    public void resetFail(String msg) {
        T.show(msg);
    }
}
